﻿/*	
	stencil - action script 3 isometric game engine.

	http://code.google.com/p/stencilas3/
	
	Copyright (c) 2010 Max Zhuravkov, All Rights Reserved.

	Permission is hereby granted, free of charge, to any person obtaining a copy of
	this software and associated documentation files (the "Software"), to deal in
	the Software without restriction, including without limitation the rights to
	use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
	of the Software, and to permit persons to whom the Software is furnished to do
	so, subject to the following conditions:

	The above copyright notice and this permission notice shall be included in all
	copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
	SOFTWARE.
*/
package stencil.core.engine.events 
{
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import stencil.core.engine.Position;
	
	import stencil.core.engine.display.IDisplayObject;
	
	/**
	 * @author Max Zhuravkov
	 */
	public class DisplayMouseEvent extends Event {
		
		public static const STN_MOUSE_OVER:String = "stnMouseOver";
		
		public static const STN_MOUSE_OUT:String = "stnMouseOut";
		
		public static const STN_MOUSE_MOVE:String = "stnMouseMove";
		
		public static const STN_ROLL_OVER:String = "stnRollOver";
		
		public static const STN_ROLL_OUT:String = "stnRollOut";
		
		public static const STN_MOUSE_DOWN:String = "stnMouseDown";
		
		public static const STN_MOUSE_UP:String = "stnMouseUp";
		
		public static const STN_CLICK:String = "stnClick";
			
		public static const STN_DOUBLE_CLICK:String = "stnDoubleClick";
		
		private var _localX:Number;
		
		private var _localY:Number;
		
		private var _globalX:Number;
		
		private var _globalY:Number;
		
		private var _positionX:Number;
		
		private var _positionY:Number;
		
		private var _positionZ:Number;
		
		private var _localPoint:Point;
		
		private var _globalPoint:Point;
		
		private var _position:Position;
		
		private var _object:IDisplayObject;
		
		private var _event:MouseEvent;
		
		//----------------------------------------------------------------
		// Constructor
		//----------------------------------------------------------------
		
		public function DisplayMouseEvent(type:String, 
										  localX:Number, localY:Number, 
										  globalX:Number,globalY:Number,
										  positionX:Number, positionY:Number,positionZ:Number,
										  object:IDisplayObject = null, event:MouseEvent = null, bubbles:Boolean = false, cancelable:Boolean=false) { 
			
			super(type, bubbles, cancelable);
			
			this._localX = localX;
			this._localY = localY;
			this._globalX = globalX;
			this._globalY = globalY;
			this._positionX = positionX;
			this._positionY = positionY;
			this._positionZ = positionZ;
			this._object = object;
			this._event = event;
		}
		
		//----------------------------------------------------------------
		// Public properties
		//----------------------------------------------------------------
		
		public function get localX():Number {
			return this._localX;
		}
		
		public function get localY():Number {
			return this._localY;
		}
		
		public function get globalX():Number {
			return this._globalX;
		}
		
		public function get globalY():Number {
			return this._globalY;
		}
		
		public function get positionX():Number {
			return this._positionX;
		}
		
		public function get positionY():Number {
			return this._positionY;
		}
		
		public function get positionZ():Number {
			return this._positionZ;
		}
		
		/**
		 * Local coordinates.
		 */
		public function get localPoint():Point {
			if (!this._localPoint) {
				this._localPoint = new Point(this.localX, this.localY);
			}
			return this._localPoint;
		}
		
		/**
		 * Global coordinates.
		 */
		public function get globalPoint():Point {
			if (!this._globalPoint) {
				this._globalPoint = new Point(this.globalX, this.globalY);
			}
			return this._globalPoint;
		}
		
		/**
		 * Grid coordinates.
		 */
		public function get position():Position {
			if (!this._position) {
				this._position = new Position(this.positionX, this.positionY, this.positionZ);
			}
			return this._position;
		}
		
		/**
		 * An object under mouse cursor if any.
		 */
		public function get object():IDisplayObject {
			return this._object;
		}
		
		//----------------------------------------------------------------
		// Public methods
		//----------------------------------------------------------------
		
		public function updateAfterEvent():void {
			if (this._event) {
				this._event.updateAfterEvent();
			}
		}
		
		public override function clone():Event { 
			return new DisplayMouseEvent(type, this.localX, this.localY, this.globalX, this.globalY, this.positionX, this.positionY, this.positionZ, this.object, this._event, this.bubbles, this.cancelable);
		} 
		
		public override function toString():String { 
			return formatToString("DisplayMouseEvent", "type", "position", "object"); 
		}
		
	}
	
}